package com.lyw.controller;

import com.lyw.entity.Student;
import com.lyw.mapper.MQStudentMapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Log4j2
@Controller
public class DataBaseController {

  @Autowired
  MQStudentMapper studentMapper;

  @Autowired
  JdbcTemplate jdbcTemplate;

  @ResponseBody
  @GetMapping("/sql")
  public String queryDB() {
    Long aLong = jdbcTemplate.queryForObject("select count(*) from student", Long.class);
    return "along -> " + aLong;
  }

  @GetMapping("/mq")
  @ResponseBody
  public Student query() {
    Student student = studentMapper.selectById(1);
    return student;
  }
}
